package com.example.admin.brainwave.utils;

import android.content.Context;


import okhttp3.Request;

public class TokenUtil {

    private static TokenUtil tokenUtil = null;

    public static TokenUtil getInstance() {
        if (tokenUtil == null)
            tokenUtil = new TokenUtil();
        return tokenUtil;
    }

    /**
     * 为请求加入access_Token以验证用户身份
     */
    public static Request.Builder addUserTokenIfPossible(Context applicationCtx, Request.Builder builder) {
        //加入身份验证信息
        if (applicationCtx != null) {
            String access_Token = SPHelper.getInstance(applicationCtx).getString("token", "");
            if (!Preconditions.isNullOrEmpty(access_Token)) {
                builder.addHeader("token", access_Token);
            }
            builder.addHeader("Content-Type", "application/json");
        }
        return builder;
    }
}
